public class Problem36 {
	public static void main(String[] args) {
		long sum = 0;

		for (int i = 1; i < 1000000; ++i) {
			String base10 = Integer.toString(i);
			if (!isPalindrome(base10))
				continue;

			StringBuilder base2 = new StringBuilder();
			int m = i;
			while (m > 0) {
				base2.append(m & 1);
				m >>= 1;
			}
		
			if (!isPalindrome(base2.toString()))
				continue;
			
			sum += i;	
		}

		System.out.println("" + sum);

		System.out.println("" + isPalindrome("585"));
	}

	private static boolean isPalindrome(String s) {
		if (s.length() <= 1)
			return true;
		return new StringBuilder(s).reverse().toString().equals(s);
	}
}
